Inside Macintosh: Imaging with QuickDraw

Previous | Chapter Top | Chapter Contents | Next

Collecting Picture Information

You can use the Picture Utilities routines described in this section to gather extensive information about pictures and to gather color information about pixel maps and bitmaps. On an 8-bit indexed device, for example, you might want your application to determine the 256 most-used colors in a picture composed of millions of colors. Your application can then use the Palette Manager (as described in Inside Macintosh: Advanced Color Imaging ) to make these colors available for the window in which your application needs to draw the picture.

You use the GetPictInfo function to gather information about a single picture, and you use the GetPixMapInfo function to gather color information about a single pixel map or bitmap. Each of these functions returns color and resolution information in a PictInfo record. A PictInfo record for a picture also contains additional information, such as the resolution of the picture, and information about the fonts and comments contained in the picture.

You can also survey multiple pictures, pixel maps, and bitmaps for this information. Use the NewPictInfo function to begin collecting pictures, pixel maps, and bitmaps for your survey. You also use NewPictInfo to specify how you would like the color, comment, and font information for the survey returned to you.

To add the information for a picture to your survey, use the RecordPictInfo function. To add the information for a pixel map or a bitmap to your survey, use the RecordPixMapInfo function. The RetrievePictInfo function collects the information about the pictures, pixel maps, and bitmaps that you have added to the survey. The RetrievePictInfo function returns this information in a PictInfo record.

When you are finished with this information, use the DisposePictInfo function to dispose of the private data structures allocated by the NewPictInfo function.

The Picture Utilities also collect information from black-and-white pictures and bitmaps, and they are supported in System 7 even by computers running only basic QuickDraw. However, when collecting color information on a computer running only basic QuickDraw, the Picture Utilities return NIL instead of a handle to a Palette or ColorTable record.

GetPictInfo

Use the GetPictInfo function to gather information about a single picture.

FUNCTION GetPictInfo (thePictHandle: PicHandle;
                                          VAR thePictInfo: PictInfo; verb: Integer;
                                          colorsRequested: Integer;
                                          colorPickMethod: Integer;
                                          version: Integer): OSErr;
thePictHandle
A handle to a picture.
thePictInfo
A pointer to a PictInfo record, which will hold information about the picture. The PictInfo record is described on PictInfo .
verb
A value indicating what type of information you want GetPictInfo to return in the PictInfo record. You can use any or all of the following constants or the sum of the integers they represent:
                CONST
                returnColorTable        = 1;    {return a ColorTable record}
                returnPalette           = 2;    {return a Palette record}
                recordComments          = 4;    {return comment information}
                recordFontInfo          = 8;    {return font information}
                suppressBlackAndWhite
                                        = 16;   {don't include black and }
                                                { white with returned colors}
Because the Palette Manager adds black and white when creating a Palette record, you can specify the number of colors you want minus 2 in the colorsRequested parameter and specify the suppressBlackAndWhite constant in the verb parameter when gathering colors destined for a Palette record or a screen.
colorsRequested
From 1 to 256, the number of colors you want in the ColorTable or Palette record returned via the PictInfo record. If you are not requesting colors (that is, if you pass the recordComments or recordFontInfo constant in the verb parameter), this function does not return colors, in which case you may instead pass 0 here.
colorPickMethod
The method by which colors are selected for the ColorTable or Palette record returned via the PictInfo record. You can use one of the following constants or the integer it represents:
                CONST
                systemMethod        = 0;    {let Picture Utilities choose }
                                            { the method (currently they }
                                            { always choose popularMethod)}
                popularMethod       = 1;    {return most frequently used }
                                            { colors}
                medianMethod        = 2;    {return a weighted distribution }
                                            { of colors}
You can also create your own color-picking method in a resource file of type 'cpmt' and pass its resource ID in the colorPickMethod parameter. The resource ID must be greater than 127.
version
Always set this parameter to 0.

DESCRIPTION

In the PictInfo record to which the parameter thePictInfo points, the GetPictInfo function returns information about the picture you specify in the thePictHandle parameter. Initially, all of the fields in a new PictInfo record are set to NIL . Relevant fields are set to appropriate values depending on the information you request using the GetPictInfo function.

Use the verb parameter to specify whether you want color information (in a ColorTable record, a Palette record, or both), whether you want picture comment information, and whether you want font information. If you want color information, be sure to use the colorPickMethod parameter to specify the method by which to select colors.

The Picture Utilities provide two color-picking methods: one (specified by the popularMethod constant) that gives you the most frequently used colors and one (specified by the medianMethod constant) that gives you the widest range of colors. Each has advantages in different situations. For example, suppose the picture of a forest image contains 400 colors, of which 300 are greens, 80 are browns, and the rest are a scattering of golden sunlight effects. If you ask for the 250 most used colors, you will probably receive all greens. If you ask for a range of 250 colors, you will receive an assortment stretching from the greens and golds to the browns, including colors in between that might not actually appear in the image. If you specify the systemMethod constant, the Picture Utilities choose the method; currently they always choose popularMethod . You can also supply a color-picking method of your own.

If your application uses more than one color-picking method, it should present the user with a choice of which method to use.

When you are finished with the information in the PictInfo record, be sure to dispose of it. Use the Memory Manager procedure DisposeHandle to dispose of the PictInfo , CommentSpec , and FontSpec records. Dispose of the Palette record by using the DisposePalette procedure. Dispose of the ColorTable record by using the DisposeCTable procedure.

SPECIAL CONSIDERATIONS

When you ask for color information, GetPictInfo takes into account only the version 2 and extended version 2 picture opcodes RGBFgCol , RGBBkCol , BkPixPat , PnPixPat , FillPixPat , and HiliteColor (as well as pixel map or bitmap data). Each occurrence of these opcodes is treated as 1 pixel, regardless of the number and sizes of the objects drawn with that color. If you need an accurate set of colors from a complex picture, create an image of the picture in an offscreen pixel map, and then call the GetPixMapInfo function (described on GetPixMapInfo ) to obtain color information about that pixel map.

The GetPictInfo function returns a bit depth of 1 on QuickTime-compressed 'PICT' files. However, when QuickTime is installed, QuickTime decompresses and displays the image correctly.

The GetPictInfo function may move or purge memory.

ASSEMBLY-LANGUAGE INFORMATION

The trap macro and routine selector for the GetPictInfo function are

Trap macro

Selector

_Pack15

$0800

RESULT CODES

pictInfoVersionErr

-11000

Version number not 0

pictInfoVerbErr

-11002

Invalid verb combination specified

cantLoadPickMethodErr

-11003

Custom pick method not in resource chain

colorsRequestedErr

-11004

Number out of range or greater than that passed to NewPictInfo

pictureDataErr

-11005

Invalid picture data

SEE ALSO

The PictInfo record is described on PictInfo , the CommentSpec record is described on CommentSpec , and the FontSpec record is described on FontSpec . The ColorTable record is described in the chapter "Color QuickDraw" in this book; the Palette record is described in the chapter "Palette Manager" in Inside Macintosh: Advanced Color Imaging . See "Application-Defined Routines," for more information about creating your own color-picking method for the colorPickMethod parameter.

The DisposePalette procedure is described in the chapter "Palette Manager" in Inside Macintosh: Advanced Color Imaging . The DisposeCTable procedure is described in the chapter "Color QuickDraw" in this book. The DisposeHandle procedure is described in the chapter "Memory Manager" in Inside Macintosh: Memory .

Listing 7-12 illustrates the use of the GetPictInfo function.

GetPixMapInfo

Use the GetPixMapInfo function to gather color information about a single pixel map or bitmap.

FUNCTION GetPixMapInfo (thePixMapHandle: PixMapHandle;
                                         VAR thePictInfo: PictInfo; verb: Integer;
                                         colorsRequested: Integer;
                                         colorPickMethod: Integer;
                                         version: Integer): OSErr;
thePixMapHandle
A handle to a pixel map or bitmap.
thePictInfo
A pointer to a PictInfo record, which will hold information about a pixel map or bitmap. The PictInfo record is described on PictInfo .
verb
A value indicating whether you want color information returned in a ColorTable record, a Palette record, or both. You can also request that black and white not be included among the returned colors. You can use any or all of the following constants or the sum of the integers they represent:
                CONST
                returnColorTable        = 1;    {return a ColorTable record}
                returnPalette           = 2;    {return a Palette record}
                suppressBlackAndWhite
                                        = 16;   {don't include black and }
                                                { white with returned colors}
Because the Palette Manager adds black and white when creating a Palette record, you can specify the number of colors you want minus 2 in the colorsRequested parameter and specify the constant suppressBlackAndWhite in the verb parameter when gathering colors destined for a Palette record or a screen.
colorsRequested
From 1 to 256, the number of colors you want in the ColorTable or Palette record returned via the PictInfo record.
colorPickMethod
The method by which colors are selected for the ColorTable or Palette record returned via the PictInfo record. You can use one of the following constants or the integer it represents:
                CONST
                systemMethod        = 0;    {let Picture Utilities choose }
                                            { the method (currently they }
                                            { always choose popularMethod)}
                popularMethod       = 1;    {return most frequently used }
                                            { colors}
                medianMethod        = 2;    {return a weighted distribution }
                                            { of colors}
You can also create your own color-picking method in a resource file of type 'cpmt' and pass its resource ID in the colorPickMethod parameter. The resource ID must be greater than 127.
version
Always set this parameter to 0.

DESCRIPTION

For the pixel map (or bitmap) whose handle you pass in the thePixMapHandle parameter, the GetPixMapInfo function returns color information in the PictInfo record that you point to in the parameter thePictInfo . Initially, all of the fields in a new PictInfo record are set to NIL . Relevant fields are set to appropriate values depending on the information you request using the GetPixMapInfo function.

Use the verb parameter to specify whether you want color information returned in a ColorTable record, a Palette record, or both, and use the colorPickMethod parameter to specify the method by which to select colors.

The Picture Utilities provide two color-picking methods: one (specified by the popularMethod constant) that gives you the most frequently used colors and one (specified by the medianMethod constant) that gives you the widest range of colors. If you specify the systemMethod constant, the Picture Utilities choose the method; currently they always choose popularMethod . You can also supply a color-picking method of your own.

When you are finished with the information in the PictInfo record, be sure to dispose of it. Use the Memory Manager procedure DisposeHandle to dispose of the PictInfo record. Dispose of the Palette record by using the DisposePalette procedure. Dispose of the ColorTable record by using the DisposeCTable procedure.

SPECIAL CONSIDERATIONS

The GetPixMapInfo function may move or purge memory.

ASSEMBLY-LANGUAGE INFORMATION

The trap macro and routine selector for the GetPixMapInfo function are

Trap macro

Selector

_Pack15

$0801

RESULT CODES

pictInfoVersionErr

-11000

Version number not 0

pictInfoVerbErr

-11002

Invalid verb combination specified

cantLoadPickMethodErr

-11003

Custom pick method not in resource chain

colorsRequestedErr

-11004

Number out of range or greater than that passed to NewPictInfo

SEE ALSO

See "Application-Defined Routines," for more information about creating your own color-picking method for the colorPickMethod parameter. The PictInfo record is described on PictInfo ; the PixMapHandle data type and the ColorTable record are described in the chapter "Color QuickDraw" in this book; the Palette record is described in Inside Macintosh: Advanced Color Imaging .

The DisposePalette procedure is described in Inside Macintosh: Advanced Color Imaging . The DisposeCTable procedure is described in the chapter "Color QuickDraw" in this book. The DisposeHandle procedure is described in the chapter "Memory Manager" in Inside Macintosh: Memory .

NewPictInfo

You can survey multiple pictures for such information as colors, picture comments, and fonts, and you can survey multiple pixel maps and bitmaps for color information. Use the NewPictInfo function to begin collecting pictures, pixel maps, and bitmaps for your survey.

FUNCTION NewPictInfo (VAR thePictInfoID: PictInfoID;
                                         verb: Integer; colorsRequested: Integer;
                                         colorPickMethod: Integer;
                                         version: Integer): OSErr;
thePictInfoID
A unique value that denotes your collection of pictures, pixel maps, or bitmaps.
verb
A value indicating what type of information you want the RetrievePictInfo function (described on RetrievePictInfo ) to return in a PictInfo record (described on PictInfo ). When collecting information about pictures, you can use any or all of the following constants or the sum of the integers they represent:
                CONST
                returnColorTable        = 1;    {return a ColorTable record}
                returnPalette           = 2;    {return a Palette record}
                recordComments          = 4;    {return comment information}
                recordFontInfo          = 8;    {return font information}
                suppressBlackAndWhite
                                        = 16;   {don't include black and }
                                                { white with returned colors}
The constants recordComments and recordFontInfo and the values they represent have no effect when gathering information about the pixel maps and bitmaps included in your survey.
Because the Palette Manager adds black and white when creating a palette, you can specify the number of colors you want minus 2 in the colorsRequested parameter and specify the constant suppressBlackAndWhite in the verb parameter when gathering colors destined for a Palette record or a screen.
colorsRequested
From 1 to 256, the number of colors you want included in the ColorTable or Palette record returned by the RetrievePictInfo function via a PictInfo record.
colorPickMethod
The method by which colors are selected for the ColorTable or Palette record included in the PictInfo record returned by the RetrievePictInfo function. You can use one of the following constants or the integer it represents:
                CONST
                systemMethod        = 0;    {let Picture Utilities choose }
                                            { the method (currently they }
                                            { always choose popularMethod)}
                popularMethod       = 1;    {return most frequently used }
                                            { colors}
                medianMethod        = 2;    {return a weighted distribution }
                                            { of colors}
You can also create your own color-picking method in a resource file of type 'cpmt' and pass its resource ID in the colorPickMethod parameter. The resource ID must be greater than 127.
version
Always set this parameter to 0.

DESCRIPTION

In the thePictInfoID parameter, the NewPictInfo function returns a unique ID number for use when surveying multiple pictures, pixel maps, and bitmaps for information.

To add the information for a picture to your survey, use the RecordPictInfo function, which is described next. To add the information for a pixel map or a bitmap to your survey, use the RecordPixMapInfo function, which is described on RecordPixMapInfo . For each of these functions, you identify the survey with the ID number returned by NewPictInfo .

Use the RetrievePictInfo function (described on RetrievePictInfo ) to return information about the pictures, pixel maps, and bitmaps in the survey. Again, you identify the survey with the ID number returned by NewPictInfo . The RetrievePictInfo function returns your requested information in a PictInfo record.

Use the verb parameter for NewPictInfo to specify whether you want to gather comment or font information for the pictures in the survey. If you want to gather color information, use the verb parameter for NewPictInfo to specify whether you want this information in a ColorTable record, a Palette record, or both. The PictInfo record returned by the RetrievePictInfo function will then include a handle to a ColorTable record or a Palette record, or handles to both. If you want color information, be sure to use the colorPickMethod parameter to specify the method by which to select colors.

The Picture Utilities provide two color-picking methods: one (specified by the popularMethod constant) that gives you the most frequently used colors and one (specified by the medianMethod constant) that gives you the widest range of colors. If you specify the systemMethod constant, the Picture Utilities choose the method; currently they always choose popularMethod . You can also supply a color-picking method of your own.

SPECIAL CONSIDERATIONS

The NewPictInfo function may move or purge memory.

ASSEMBLY-LANGUAGE INFORMATION

The trap macro and routine selector for the NewPictInfo function are

Trap macro

Selector

_Pack15

$0602

RESULT CODES

pictInfoVersionErr

-11000

Version number not 0

pictInfoVerbErr

-11002

Invalid verb combination specified

cantLoadPickMethodErr

-11003

Custom pick method not in resource chain

colorsRequestedErr

-11004

Number out of range or greater than that passed to NewPictInfo

SEE ALSO

The PictInfo record is described on PictInfo , the CommentSpec record is described on CommentSpec , and the FontSpec record is described on FontSpec . The ColorTable record is described in the chapter "Color QuickDraw" in this book; the Palette record is described in Inside Macintosh: Advanced Color Imaging . See "Application-Defined Routines," for more information about creating your own color-picking method for the colorPickMethod parameter.

RecordPictInfo

To add a picture to an informational survey of multiple pictures, use the RecordPictInfo function.

FUNCTION RecordPictInfo (thePictInfoID: PictInfoID;
                                         thePictHandle: PicHandle): OSErr;
thePictInfoID
The ID number--returned by the NewPictInfo function--that identifies the survey to which you are adding the picture. The NewPictInfo function is described on NewPictInfo .
thePictHandle
A handle to the picture being added to the survey.

DESCRIPTION

The RecordPictInfo function adds the picture you specify in the parameter  thePictHandle to the survey of pictures identified by the parameter thePictInfoID . Use RecordPictInfo repeatedly to add additional pictures to your survey.

After you have collected all of the pictures you need, use the RetrievePictInfo function, described on RetrievePictInfo , to return information about pictures in the survey.

SPECIAL CONSIDERATIONS

When you ask for color information, RecordPictInfo takes into account only the version 2 and extended version picture opcodes RGBFgCol , RGBBkCol , BkPixPat , PnPixPat , FillPixPat , and HiliteColor . Each occurrence of these opcodes is treated as 1 pixel, regardless of the number and sizes of the objects drawn with that color. If you need an accurate set of colors from a complex picture, create an image of the picture in an offscreen pixel map, and then call the GetPixMapInfo function (described on GetPixMapInfo ) to obtain color information about that pixel map.

The RecordPictInfo function may move or purge memory.

ASSEMBLY-LANGUAGE INFORMATION

The trap macro and routine selector for the RecordPictInfo function are

Trap macro

Selector

_Pack15

$0403

RESULT CODES

pictInfoIDErr

-11001

Invalid picture information ID

pictureDataErr

-11005

Invalid picture data

RecordPixMapInfo

To add a pixel map or bitmap to an informational survey of multiple pixel maps and bitmaps, use the RecordPictInfo function.

FUNCTION RecordPixMapInfo (thePictInfoID: PictInfoID;
                                          thePixMapHandle: PixMapHandle): OSErr;
thePictInfoID
The ID number--returned by the NewPictInfo function--that identifies the survey to which you are adding the pixel map or bitmap. The NewPictInfo function is described on NewPictInfo .
thePixMapHandle
A handle to a pixel map (or bitmap) to be added to the survey.

DESCRIPTION

The RecordPixMapInfo function adds the pixel map or bitmap you specify in the parameter thePixMapHandle to the survey identified by the parameter thePictInfoID . Use RecordPictInfo repeatedly to add additional pixel maps and bitmaps to your survey.

After you have collected all of the images you need, use the RetrievePictInfo function, described on RetrievePictInfo , to return information about all the images in the survey.

SPECIAL CONSIDERATIONS

The RecordPixMapInfo function may move or purge memory.

ASSEMBLY-LANGUAGE INFORMATION

The trap macro and routine selector for the RecordPixMapInfo function are

Trap macro

Selector

_Pack15

$0404

RESULT CODES

pictInfoIDErr

-11001

Invalid picture information ID

pictureDataErr

-11005

Invalid picture data

RetrievePictInfo

Use the RetrievePictInfo function to return information about all the pictures, pixel maps, and bitmaps included in a survey.

FUNCTION RetrievePictInfo (thePictInfoID: PictInfoID;
                                          VAR thePictInfo: PictInfo;
                                          colorsRequested: Integer): OSErr;
thePictInfoID
The ID number--returned by the NewPictInfo function--that identifies the survey of pictures, pixel maps, and bitmaps. The NewPictInfo function is described on NewPictInfo .
thePictInfo
A pointer to the PictInfo record that holds information about the pictures or images in the survey. The PictInfo record is described on PictInfo .
colorsRequested
From 1 to 256, the number of colors you want returned in the ColorTable or Palette record included in the PictInfo record.

DESCRIPTION

In a PictInfo record that you point to in the parameter thePictInfo , the RetrievePictInfo function returns information about all of the pictures and images collected in the survey that you specify in the parameter thePictInfoID .

After using the NewPictInfo function to create a new survey, and then using RecordPictInfo to add pictures to your survey and RecordPixMapInfo to add pixel maps and bitmaps to your survey, you can call RetrievePictInfo .

When you are finished with the information in the PictInfo record, be sure to dispose of it. You can dispose of the Palette record by using the DisposePalette procedure. You can dispose of the ColorTable record by using the DisposeCTable procedure. You can dispose of other allocations with the DisposeHandle procedure. You should also use the DisposePictInfo function (described next) to dispose of the private data structures created by the NewPictInfo function.

SPECIAL CONSIDERATIONS

The RetrievePictInfo function may move or purge memory.

ASSEMBLY-LANGUAGE INFORMATION

The trap macro and routine selector for the RetrievePictInfo function are

Trap macro

Selector

_Pack15

$0505

RESULT CODES

pictInfoIDErr

-11001

Invalid picture information ID

colorsRequestedErr

-11004

Number out of range or greater than that passed to NewPictInfo

SEE ALSO

The DisposePalette procedure is described in Inside Macintosh: Advanced Color Imaging . The DisposeCTable procedure is described in the chapter "Color QuickDraw" in this book. The DisposeHandle procedure is described in the chapter "Memory Manager" in Inside Macintosh: Memory .

DisposePictInfo

When you are finished gathering information from a survey of pictures, pixel maps, or bitmaps, use the DisposePictInfo function to dispose of the private data structures allocated by the NewPictInfo function. The DisposePictInfo function is also available as the DisposPictInfo function.

FUNCTION DisposePictInfo (thePictInfoID: PictInfoID): OSErr;
thePictInfoID
The unique identifier returned by NewPictInfo .

DESCRIPTION

The DisposePictInfo function disposes of the private data structures allocated by the NewPictInfo function, which is described on NewPictInfo .

The DisposePictInfo function does not dispose of any of the handles returned to you in a PictInfo record by the RetrievePictInfo function, which is described on RetrievePictInfo . Instead, you can dispose of a Palette record by using the DisposePalette procedure. You can dispose of a ColorTable record by using the  DisposeCTable procedure. You can dispose of other allocations with the DisposeHandle procedure.

SPECIAL CONSIDERATIONS

The DisposePictInfo function may move or purge memory.

ASSEMBLY-LANGUAGE INFORMATION

The trap macro and routine selector for the DisposePictInfo function are

Trap macro

Selector

_Pack15

$0206

RESULT CODE

pictInfoIDErr

-11001

Invalid picture information ID

SEE ALSO

The DisposePalette procedure is described in Inside Macintosh: Advanced Color Imaging . The DisposeCTable procedure is described in the chapter "Color QuickDraw" in this book. The DisposeHandle procedure is described in the chapter "Memory Manager" in Inside Macintosh: Memory .


© 1997 Apple Computer, Inc.

Previous | Chapter Top | Chapter Contents | Next